package com.uzai.console.web.pyq;

import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSort;
import com.uzai.common.enums.DeviceTypeEnum;
import com.uzai.console.annotation.SystemLogType;
import com.uzai.console.dto.pyq.pyqmaterial.PyqMaterialDto;
import com.uzai.console.dto.pyq.pyqmaterial.PyqMaterialIdDto;
import com.uzai.console.dto.pyq.pyqmaterial.PyqMaterialQuery;
import com.uzai.console.dto.pyq.pyqmaterial.TurnlinkDto;
import com.uzai.console.enums.OperationTypeEnum;
import com.uzai.console.enums.SystemModelEnum;
import com.uzai.console.service.pyq.PyqMaterialService;
import com.uzai.console.service.qiniu.QiniuService;
import com.uzai.console.service.sysmaterial.SysMaterialService;
import com.uzai.console.vo.feign.turnlink.SimpleTurnlinkVo;
import com.uzai.console.vo.pyq.pyqmaterial.PyqMaterialVo;
import com.uzai.console.vo.qiniu.QiniuConfigUploadFileVo;
import com.uzai.console.vo.sysmaterial.UploadFileVo;
import com.uzai.console.web.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

/**
 * 素材
 * @author liuqi
 * @date 2021年08月16日 15:11
 */
@Api(value = "素材",tags = "个人微信|朋友圈|素材")
@ApiSort(31)
@RestController
public class PyqMaterialController extends BaseController {
    private Logger logger = LoggerFactory.getLogger(PyqMaterialController.class);

    @Autowired
    private PyqMaterialService pyqMaterialService;
    @Autowired
    private QiniuService qiniuService;
    @Autowired
    private SysMaterialService sysMaterialService;

    @ApiOperation(value = "分页查询素材列表", notes = "分页查询素材列表", response = PyqMaterialVo.class)
    @ApiOperationSupport(order = 1)
    @PostMapping("/pyqMaterial/findPyqMaterialList")
    public Object findPyqMaterialList(@RequestBody PyqMaterialQuery pyqMaterialQuery){
        pyqMaterialQuery.setDeviceType(DeviceTypeEnum.DT_PC_WECHAT.getKey());
        return pyqMaterialService.findPyqMaterialList(pyqMaterialQuery);
    }

    @SystemLogType(model = SystemModelEnum.PyqMaterial, type = OperationTypeEnum.ADD)
    @ApiOperation(value = "添加素材", notes = "添加素材")
    @ApiOperationSupport(order = 2)
    @PostMapping("/pyqMaterial/addPyqMaterial")
    public Object addPyqMaterial(@RequestBody PyqMaterialDto pyqMaterialDto){
        pyqMaterialService.addPyqMaterial(pyqMaterialDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.PyqMaterial, type = OperationTypeEnum.UPDATE)
    @ApiOperation(value = "编辑素材", notes = "编辑素材" )
    @ApiOperationSupport(order = 3)
    @PostMapping("/pyqMaterial/updatePyqMaterial")
    public Object updatePyqMaterial(@RequestBody PyqMaterialDto pyqMaterialDto){
        pyqMaterialService.updatePyqMaterial(pyqMaterialDto);
        return true;
    }

    @SystemLogType(model = SystemModelEnum.PyqMaterial, type = OperationTypeEnum.DELETE)
    @ApiOperation(value = "删除", notes = "删除")
    @ApiOperationSupport(order = 4)
    @PostMapping("/pyqMaterial/deletePyqMaterial")
    public Object deletePyqMaterial(@RequestBody PyqMaterialIdDto pyqMaterialIdDto){
        pyqMaterialService.deletePyqMaterial(pyqMaterialIdDto);
        return true;
    }

    @ApiOperation(value = "查询素材详情", notes = "查询素材详情", response = PyqMaterialVo.class)
    @ApiOperationSupport(order = 5)
    @PostMapping("/pyqMaterial/findPyqMaterial")
    public Object findPyqMaterial(@RequestBody PyqMaterialIdDto pyqMaterialIdDto){
        return pyqMaterialService.findPyqMaterial(pyqMaterialIdDto);
    }

    @ApiOperation(value = "上传本地图片", notes = "上传本地图片", response = UploadFileVo.class)
    @ApiOperationSupport(order = 6)
    @PostMapping("/pyqMaterial/uploadImage")
    public Object uploadImage(MultipartFile file){
        Long merId = getLoginInfo().getMerId();
        return sysMaterialService.uploadFile(file, merId);
    }

    @ApiOperation(value = "获取商品转链信息", notes = "获取商品转链信息", response = SimpleTurnlinkVo.class)
    @ApiOperationSupport(order = 7)
    @PostMapping("/pyqMaterial/getGoodInfo")
    public Object getGoodInfo(@RequestBody TurnlinkDto turnlinkDto){
        return pyqMaterialService.getGoodInfo(turnlinkDto);
    }



}
